<?php
// +----------------------------------------------------------------------
// | 用户申请代理
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;

class UserApplyAgent extends Model
{
	use \base\model\ModelTrait;
	/**
    * 获取时只取字段
    */
	public $fields = [];
	/**
    * 错误信息
    */
	public $errorInfo;
	/**
    * 验证规则
    */
	protected $rule = [
		'uid|用户id'=>'require|integer',
		'name|姓名'=>'require',
		'phone|手机号'=>'require|integer|min:11',
    	'card_no|身份证号' => 'require|min:15'
	];
	
	/**
     * 审核
     * @param type $ids
     * @param type $v
     * @return type
     */
	public function approval($id)
    {
    	$agent = self::get($id);
		$agent->status = 1;
		$agent->status_time = date("Y-m-d H:i:s");
		
		$data['is_partner']= 1;
		$data['realname']= $agent['name'];
		$data['phone']= $agent->phone;
		$data['card_no']= $agent->card_no;
		if( model('user')->where('id',$agent->uid)->update($data) ){
			$agent->save();
			return true;
		}
		return false;
    }
	
}
